package com.cn.wanxi.servlet.message;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.MessageModel;
import com.cn.wanxi.service.IMessageService;
import com.cn.wanxi.service.impl.MessageServiceImpl;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/back/message/findAll")
public class MessageFindAllServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        取得数据
        String userName = req.getParameter("userName");
        String messageName = req.getParameter("messageName");
        String email = req.getParameter("email");
        String content = req.getParameter("content");
        String view = req.getParameter("view");
        String time = req.getParameter("time");
        String lowView = req.getParameter("lowView");
        String topView = req.getParameter("topView");
        String lowTime = req.getParameter("lowTime");
        String topTime = req.getParameter("topTime");

//        封装数据
        MessageModel messageModel = new MessageModel();
        messageModel.setUserName(userName);
        messageModel.setMessageName(messageName);
        messageModel.setEmail(email);
        messageModel.setContent(content);
        messageModel.setView(view);
        messageModel.setTime(time);
        messageModel.setLowView(lowView);
        messageModel.setTopView(topView);
        messageModel.setLowTime(lowTime);
        messageModel.setTopTime(topTime);

        IMessageService iMessageService = new MessageServiceImpl();
        List<MessageModel> list = iMessageService.findAll(messageModel);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list", list);
        resp.getWriter().println(jsonObject);

    }
}
